<template>
  <div class="qualityTestContainer">
    <!--头部bar开始-->
    <CommonBar :options="options"></CommonBar>
    <!--头部bar结束-->
    <!-- <ul class="qualityTest_ul">
      <li
        class="qualityTest_li"
        v-for="item in menulist"
        :key="item.id"
        @click="routeToName(item.name)"
      >
        <div class="textcontent" :style="{'background':item.background}">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
      </li>
    </ul>-->
    <!--根据权限判断质检考核-->
    <ul class="qualityTest_ul">
      <li
        v-for="item in menu"
        :key="item.id"
        class="qualityTest_li"
        @click="routeToName(item.path)"
      >
        <div class="textcontent textcontent1" v-if="item.path=='/projectCompanyList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
        <div class="textcontent textcontent2" v-if="item.path=='/projectList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
        <div class="textcontent textcontent3" v-if="item.path=='/managerList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
        <div class="textcontent textcontent4" v-if="item.path=='/cleanerList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
        <div class="textcontent textcontent5" v-if="item.path=='/profitList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
        <div class="textcontent textcontent6" v-if="item.path=='/deviceList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
        <div class="textcontent textcontent7" v-if="item.path=='/administrativeList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
        <div class="textcontent textcontent8" v-if="item.path=='/financeList'">
          <van-image :src="item.icon" class="home_icon" />
          <span>{{item.name}}</span>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import CommonBar from "../common/commonBar";
import { mapState } from "vuex";
export default {
  components: {
    CommonBar
  },
  computed: {
    ...mapState({
      token: state => state.Authorization,
      role_id: state => state.userData.role_id,
      muneid: state => state.muneid
    })
  },
  data() {
    return {
      noauth: require("../../../static/image/noauth.png"),
      options: {
        type: "icon",
        centerText: "考核管理",
        iconNname: "wap-home",
        lefttype: "left"
      },
      //首页数据
      menulist: [
        {
          id: 1,
          name: "项目公司考核",
          icon: require("../../../static/image/check_four.png")
        },
        {
          id: 2,
          name: "项目部考核",
          icon: require("../../../static/image/check_one.png")
        },
        {
          id: 3,
          name: "管理员考核",
          icon: require("../../../static/image/check_two.png")
        },
        {
          id: 4,
          name: "保洁员考核",
          icon: require("../../../static/image/check_three.png")
        },
        {
          id: 5,
          name: "利润考核",
          icon: require("../../../static/image/check_three.png")
        },
        {
          id: 6,
          name: "设备考核",
          icon: require("../../../static/image/check_three.png")
        },
        {
          id: 7,
          name: "行政考核",
          icon: require("../../../static/image/check_three.png")
        },
        {
          id: 8,
          name: "财务考核",
          icon: require("../../../static/image/check_three.png")
        }
      ],
      menu: []
    };
  },
  created() {
    this.home();
  },
  destroyed() {
    var that = this;
    document.removeEventListener("backbutton", that.backbutton, false);
  },
  mounted() {
    var that = this;
    document.addEventListener("backbutton", that.backbutton, false);
  },
  methods: {
    backbutton() {
      if (this.$route.path == "/checkIndex") {
        this.$router.push({ path: "/home" });
      }
    },
    home() {
      this.$toast.loading({
        mask: true,
        message: "加载中..."
      });
      this.params = {
        type: 2,
        parent_id: this.muneid,
        role_id: this.role_id,
        token: this.token
      };
      this.$http
        .get(`${this.$basePath}?service=App.Account.GetAuthMenuList`, {
          params: this.params
        })
        .then(res => {
          if (res.ret == 200) {
            this.$toast.clear();
            this.menu = res.data;
            console.log(this.menu);
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    routeToName(path, id) {
      switch (path) {
        case "/projectCompanyList":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/projectList":
          this.$router.push({
            //核心语句
            path: path
          });
          break;
        case "/managerList":
          this.$router.push({
            //核心语句
            path: path

            //跳转的路径
          });
          break;
        case "/warnMessage":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/cleanerList":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/profitList":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/deviceList":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/administrativeList":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;

        case "/financeList":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;

        default:
          this.$toast({
            message: "功能暂未开发"
          });
          break;
      }
    }
  }
  //获取首页数据
};
</script>
<style lang="less" scoped>
@import "../../assets/css/check";
</style>